<?php

namespace core;

class User
{
	private $usersTypes = array();
	private $defaultUserType = "";

	public function __construct()
	{
		$usersTypes = service("db")->Select("*")->From("_users_types")->Run();

		$res = array();
		foreach ($usersTypes as $item)
		{
			$res[$item['type']] = $item;

			if ((int)$item['default'] === 1)
			{
				$default = $item['type'];
			}
		}

		if (isset($default))
		{
			$this->defaultUserType = $item['type'];
		}
		else
		{
			service("debug")->Error("Default user type not set");
		}

		$this->usersTypes = $res;

		return true;
	}

	public function CheckIn()
	{

	}

	public function CheckOut()
	{

	}

	public function GetUser()
	{

	}

	public function GetUserType()
	{
		//Simplest role
		if (!core("Registry")->WasSet("userType", "user"))
		{
			core("Registry")->Set("userType", $this->defaultUserType, 'user');
		}

		$type = core("Registry")->Get("userType", "user");

		return $this->usersTypes[$type];
	}
}